/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package weka;

import java.awt.event.ActionEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import weka.classifiers.trees.J48;
import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;

/**
 *
 * @author Utilisateur
 */
public class VisualisationAction extends AbstractAction{
    
    private MainWindow fenetre;
    public VisualisationAction(MainWindow fenetre, String texte)
    {
        super(texte);
        this.fenetre = fenetre;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        //Visualisation j48 = new Visualisation(fenetre.getFile());
        //j48.setVisible(true);
        DataSource source = null;
        try {
            source = new DataSource(fenetre.getFile());
        } catch (Exception ex) {
            Logger.getLogger(VisualisationAction.class.getName()).log(Level.SEVERE, null, ex);
        }
    Instances data = null;
        try {
            data = source.getDataSet();
        } catch (Exception ex) {
            Logger.getLogger(VisualisationAction.class.getName()).log(Level.SEVERE, null, ex);
        }
    if (data.classIndex() == -1)
      data.setClassIndex(data.numAttributes() - 1);
    J48 base = new J48();
        try {
            base.buildClassifier(data);
        } catch (Exception ex) {
            Logger.getLogger(VisualisationAction.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        PrefuseTree tree = new PrefuseTree();
        try {
            tree.display(base.graph(), "Visualisation");
        } catch (Exception ex) {
            Logger.getLogger(VisualisationAction.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
}
